<?php 
if(!isset($_SESSION)) 
{ 
	session_start(); 
}
$_SESSION['action'] = "mybin_senddoc";
if(!isset($_REQUEST['page'])){
$list["a.Tile"]="DESC";
$list["a.Timecreate"]="DESC";
$list["a.TimeApprove"]="DESC";
$list["a.IDApproveDoc"]="DESC";
//$str=$_SESSION['sortn'];
//if($str==''){
$str="a.Timecreate";
$_SESSION['sortn']=$str;
//}
$_SESSION['sort']=$list;
}else{
	$str=$_SESSION['sortn'];
	$list=$_SESSION['sort'];
}

if(array_key_exists("page",$_GET))
    $page  = $_GET['page'];
else
    $page = 1;
    
$sql="SELECT SumMoney,IDApproveDoc,Tile,IDTypeDoc,DATE_FORMAT(a.TimeApprove, '%Y-%m-%d') as TimeApprove,DATE_FORMAT(a.Timecreate, '%Y-%m-%d') as Timecreate    from approvedoc a WHERE CONVERT(a.IDStatus USING utf8) = 6 AND CONVERT(a.IDEmployee USING UTF8) = CONVERT(".$id_employee."  USING UTF8)";
$query  = mysql_query($sql." ORDER BY ".$str." ".$list[$str] );
$number_of_page = ceil ( mysql_num_rows( $query ) / $rows_per_page ); 

if($page>$number_of_page && $page!=1)
    $page=$number_of_page;
?>
<script type="text/javascript">
function sort(page,str,co)
{
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
										  if (xmlhttp.readyState==4 && xmlhttp.status==200){
										    	document.getElementById("content").innerHTML=xmlhttp.responseText;
										  }
									  }
	xmlhttp.open("GET","ajax/list/sort_mybin_send.php?page="+page+"&str="+str+"&co="+co,true);
	xmlhttp.send();
}

</script>
<div class="nav_top">
       		<div class="nav_tit"><?php echo $l_e_approval;?></div>     
            <div class="rehome"><a href="mainPhone.php"><?php echo $l_menu?></a></div>       
       	</div>
<div class="main_content">
    <h3 class="atitle"><a href="menu.php?append=mybinDocument"><?=$l_re_bin ?></a> &rarr; <?=$l_se_document?></h3>
    <div style="width:100%" id="content" >
    <table class="tcontent" cellpadding="5" cellspacing="0">
        <tr class="trtit">
        	<td width="10px"><input type="checkbox" name="chonhet" id="chonhet" onclick="clickChonHet(this);"/></td>
        	<td width="10px" ><?=$l_no?></td>
            <td width="20%"><?=$l_document_form?></td>
            <td ><a style="cursor:pointer;" onclick="sort(<?=$page?>,'a.Tile','1')"><?=$l_title?></a></td>
			<td width="15%" ><a style="cursor:pointer;" onclick="sort(<?=$page?>,'a.Timecreate','1')"><?=$l_created_date?></a></td>
			<td width="15%"><a style="cursor:pointer;" onclick="sort(<?=$page?>,'a.TimeApprove','1')"><?=$l_approve_date."/".$l_declinedate?></a></td>
        </tr>
        <?php 
        if(mysql_num_rows($query)>0){
        	$i = 0; 
			while ($row=mysql_fetch_array($query)){
				if ( $i >= $page_start  ) 
				{ 
			    	if($row[IDTypeDoc]==7)$document = $l_vacation_form;
			    	else if($row[IDTypeDoc]==12)$document = $l_assignment_report;
			    	else if($row[IDTypeDoc]==13)$document = $l_purchase_order;
			    	else if($row[IDTypeDoc]==14)$document = $l_daily_report;
			    	else if($row[IDTypeDoc]==15)$document = $l_business_trip_report;
			    	else if($row[IDTypeDoc]==16)$document = $l_weekly_report;
			    	else if($row[IDTypeDoc]==17)$document = $l_susqence_payment_request;
			    
			?>
				<tr bgcolor="#ffffff" class="highlighter">
					<td><input type="checkbox"  name="chon" value="<?php echo $row[IDGroupApprove];?>" /></td>
					<td align="center"><?=($i+1)?></td>
					<td ><div  align="left" ><?php echo $document;?></div></td>
					<td >
						<div  align="left" >
							<a style="color:blue;" href="view.php?action=<?=$_SESSION['action']?>&id=<?=$row[IDApproveDoc]?>&type=<?=$row[IDTypeDoc]?>&page=<?=$page?>"><?=$row[Tile]?> </a>
							
							
							<?php /*if ($row[isView]==0){
								echo "<span style='font-size:10px;'><span style='color: rgb(0, 0, 255); '><em>  [".$l_new."]</em></span></span>";
							}*/
							?>
							<p style="float:right">
						<?php 
							if($row[IDTypeDoc]==13 || $row[IDTypeDoc]==15 || $row[IDTypeDoc]==17){
								if($row[SumMoney]>0){
									echo " [ ".number_format($row[SumMoney])." ]";
								}else{
									if($row[IDTypeDoc]==15 || $row[IDTypeDoc]==13){
										$s1="select sum(buying_document.total) as tongtien from approvedoc,buying_document where approvedoc.IDApproveDoc=buying_document.document_id and approvedoc.IDApproveDoc='".$row[IDApproveDoc]."' GROUP BY approvedoc.IDApproveDoc";
										$k1=mysql_query($s1);
										while ($r1=mysql_fetch_array($k1)){
											if($r1[tongtien]>0){
												echo "[".number_format($r1[tongtien])."]";
											}
										}
									}else if($row[IDTypeDoc]==17){
										$s1="select sum(ap_advance.money) as tongtien from approvedoc,ap_advance where approvedoc.IDApproveDoc=ap_advance.document_id and approvedoc.IDApproveDoc='".$row[IDApproveDoc]."' GROUP BY approvedoc.IDApproveDoc";
										$k1=mysql_query($s1);
										while ($r1=mysql_fetch_array($k1)){
											if($r1[tongtien]>0){
												echo " [ ".number_format($r1[tongtien])." ]";
											}
										}
									}
								}
							}
						?>
						</p>
						</div>
						
					</td>
				
					<td><?=$row[Timecreate]?></td>
					<td ><?=$row[TimeApprove]?></td>
				</tr>
			<?php 	}
			
				$i++; 
				
				if ($i >= $page_end) 
				{ 
				break; 
				} 
			}
        }
        ?>
				
		<?php if ( $number_of_page > 1 ) 
		{ 
			?>
			 <tr>
				<td colspan="6" class="bt_td_main">
				
				<span style="background:#fff; padding:1px; display: inline-block;">
			<?php 
			if ($page==1)
				$p=2;
			else if ($page==$number_of_page)
				$p=$number_of_page-1;
			else $p=$page;
			if($page!=1){?>
				<a onclick="sort(1,'<?=$str?>',0)" ><span class='button_next'><?php echo "<<";?></span> </a>
				<a onclick="sort(<?=($page-1)?>,'<?=$str?>',0)" ><span class='button_next'><?php echo "<";?></span> </a>
			<?php  }
			else{
				//echo "<span class='button_next'><<<</span>"; 
				//echo "<span class='button_next'><<</span>";
			}
			for ( $i = $p-1; $i <= $p+1; $i++ ) {	
					if ($i<=$number_of_page && $i>0)
					
						if ($i==$page){
							echo "<span class='button_next' style='color:#324fa2;font-weight:bold;'>".$i."</span>"; 
						}else{
						?>
							<a onclick="sort(<?=$i?>,'<?=$str?>',0)" ><span class="button_next" style="color: #508e21;">
							<?php 
							echo $i;
							?>
							</span> </a>
						<?php 
						}
					?>
				
			<?php 
					}
				
				if($page!=$number_of_page){ ?>
					<a onclick="sort(<?=($page+1)?>,'<?=$str?>',0)"><span class='button_next'><?php echo ">";?></span> </a>
					<a onclick="sort(<?=($number_of_page)?>,'<?=$str?>',0)" ><span class='button_next'><?php echo ">>";?></span> </a>
				<?php }
				else{
					//echo "<span class='button_next'>>></span> ";
					//echo "<span class='button_next'>>>></span> ";
				}
				?>
				</span>
			</td>
		</tr>
				<?php 
			}
		
			
			?>
    </table>
    </div>
</div>